<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加教学材料类型</title>
</head>
<body>
	<jsp:include page="../navbar.html" />
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-1 col-md-offset-3">
				<a href="teachingMaterialsTypeServlet?method=list">
					<button type="button" class="btn btn-default"><em class="fa fa-chevron-left"></em> 返回</button>
				</a>
			</div>
		</div>
    	<div class="row mt15">
			<div class="col-md-6 col-md-offset-3">
				<div class="panel">
                	<div class="panel-body">
                  		<h4 class="page-header mt0">教学材料类型</h4>
                  			<form name="typeform" role="form" action="teachingMaterialsTypeServlet" method="post"  onsubmit="return check(this);" class="form-horizontal mt20">
	                  	    <fieldset>
				              <div class="form-group">
				                  <label class="col-md-2 control-label">ID</label>
				                  <div class="col-md-9">
				                     <input class="form-control" type="text" name="id" placeholder="请输入类型ID" />
				                  </div>
				               </div> 
			                </fieldset>
		               		<fieldset>
			               		<div class="form-group">
			                  		<label class="col-md-2 control-label">名称</label>
		                  			<div class="col-md-9">
		                     			<input class="form-control" type="text" name="name" placeholder="请输入类型名称" />
		                  			</div>
		               			</div>	
		               		</fieldset> 
		                	<fieldset>
			               		<div class="form-group">
			                  		<label class="col-md-2 control-label">说明</label>
			                  		<div class="col-md-9">
			                     		<input class="form-control" type="text" name="explain" placeholder="请输入类型说明" />
			                  		</div>
			               		</div>	
		               		</fieldset>   
		               		<fieldset>
			              		<div class="form-group">
			               			<label class="col-md-2 control-label">备注</label>
				               		<div class="col-md-9">
					               		<div class="checkbox c-checkbox">
					                        <label>
					                           <input type="checkbox" checked="checked" name="ishand" value="true">
					                           <span class="fa fa-check"></span>是否必交</label>
				                     	</div>
			               			</div>
			               		</div>
		               		</fieldset>  
		               		<fieldset>
			              		<div class="form-group">
			               			<label class="col-md-2 control-label">备注</label>
				               		<div class="col-md-9">
			               				<textarea class="form-control no-resize" name="mark" placeholder="请输入类型备注" rows="6"></textarea>
			               			</div>
			               		</div>
		               		</fieldset> 
		               		<div class="col-md-10 col-md-offset-1">
		               			<div class="col-md-6">
		               				<button type="submit" class="btn btn-primary btn-block" name="method" value="add">添加</button> 
		               			</div>
		               			<div class="col-md-6">
		               				<button type="reset" class="btn btn-default btn-block">重置</button> 
		               			</div>
		               		</div>
		               	</form>
               		</div>
            	</div>
         	</div>
       </div>
    </div>
    <script>
		function check(typeform) {  		
			if(typeform.id.value=="") {  
		        swal("类型 ID不能为空","请重新输入","warning");  
		        return false;  
		    }  
		    else if(!isNumber(typeform.id.value)) {
		    	swal("类型 ID不合法","请重新输入","warning");  
		        return false;  
		    }
		    else if(typeform.name.value=="") {  
		    	swal("类型名称不能为空","请重新输入","warning");   
		        return false;  
		    }   
		    else if(typeform.explain.value=="") {  
		   	    swal("类型说明不能为空","请重新输入","warning");   
		        return false;  
		    }
		    else {
		    	if(document.getElementByName("ishand").checked){
					typeform.ishand.value = true;
				}
				else {
					typeform.ishand.value = false;
				}
		    	return true;  
		    }
		}   
		
		function isNumber(str)          // 判断是否为非负整数  
		{  
		    var rx = /^[0-9]+$/;  
		    return rx.test(str);  
		}
		
		<%
		String error = (String)request.getAttribute("error");
		if(error != null) {%>
			swal("<%=error %>", "失败", "warning");
		<%
			request.removeAttribute("error");
		} %>
	</script>
</body>
</html>